package com.example.demo.database.mywait;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;

public class Join {
	public static void main(String[] args) throws InterruptedException {
		Thread pr = Thread.currentThread();
		for (int i = 0; i < 20; i++) {
			SonThread sonThread = new SonThread(pr);
			sonThread.start();
			pr = sonThread;
			
		}
		TimeUnit.SECONDS.sleep(2);
		System.out.println("主线程名称：["+Thread.currentThread().getName()+"]");

	}
	static class SonThread extends Thread{
		Thread thread;
		public SonThread(Thread t) {
			thread = t;
		}
		
		@Override
		public void run() {
			System.out.println("前个线程名称：["+thread.getName()+"]"+"子线程名称：["+Thread.currentThread().getName()+"]");
			try {
				thread.join();
				System.err.println(Thread.currentThread().getName());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
